<template>
  <div class="page-home">
    <div class="home-entry">
      <div class="container">
        <!-- 左侧分类 -->
        <home-category></home-category>
        <!-- banner轮播图 -->
        <home-banner></home-banner>
        <!-- 新鲜好物 -->
        <home-pannel title="新鲜好物" sub-title="新鲜出炉 品质靠谱">
          <template #right>
            <xtx-more></xtx-more>
          </template>
          <template #pannel>
            <ul ref="pannel" class="goods-list">
              <li v-for="item in panneNewlList" :key="item.id">
                <RouterLink :to="`/goods/${item.id}`">
                  <img :src="item.picture" alt="" />
                  <p class="name">{{ item.name }}</p>
                  <p class="price">&yen;{{ item.price }}</p>
                </RouterLink>
              </li>
            </ul>
          </template>
        </home-pannel>

        <!-- 人气推荐 -->
        <home-pannel title="人气推荐" sub-title="人气爆款 不容错过">
          <template #pannel>
            <ul  class="goods-hot-list">
              <li v-for="item in pannelHotList" :key="item.id">
                <RouterLink to="/">
                <!-- v-imgLazy="item.picture" 自定义指令 图片懒加载 -->
                  <img src="" alt="" v-imgLazy="item.picture">
                  <p class="name">{{item.title}}</p>
                  <p class="desc">{{item.alt}}</p>
                </RouterLink>
              </li>
            </ul>
          </template>
        </home-pannel>
      </div>
    </div>
  </div>
</template>

<script>
import HomeCategory from './components/home-category.vue'
import HomeBanner from './components/home-banner.vue'
import HomePannel from './components/home-pannel.vue'
import { findHot } from '@/api/home'
import { ref } from 'vue'
import { goodsNew } from './service/goods-new.js'
export default {
  name: 'home',
  components: {
    HomeCategory,
    HomeBanner,
    HomePannel
  },
  setup () {
    // 新鲜好物
    // const panneNewlList = ref([])
    // async function pannelLiatFn () {
    //   const res = await findNew()
    //   panneNewlList.value = res.data.result
    //   // console.log(res.data)
    // }
    const { panneNewlList } = goodsNew()

    // 人气推荐
    const pannelHotList = ref([])
    async function pannelHotListFn () {
      const res = await findHot()
      pannelHotList.value = res.data.result
    }
    pannelHotListFn()

    return {
      pannelHotList,
      panneNewlList,
      pannelHotListFn
    }
  }
}
</script>

<style scoped lang='less'>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  // margin-bottom: 20px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }
    .price {
      color: @priceColor;
    }
  }
}
.goods-hot-list {
  display: flex;
  justify-content: space-between;
  height: 426px;
  li {
    width: 306px;
    height: 406px;
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
    }
    .desc {
      color: #999;
      font-size: 18px;
    }
  }
}
</style>
